﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
<#assign base=request.contextPath  />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>

    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css">
    <link rel="stylesheet" href="${base}/frame/static/css/style.css">
    <link rel="icon" href="${base}/frame/static/image/code.png">
    <style>
        html { overflow-x: hidden; overflow-y: auto; }
    </style>

</head>
<body class="body">
<div class="ziyemianbiju">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>企业车辆</legend>
    </fieldset>
    <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
        <div class="my-btn-box">
            <span style="height: 50px;">

               <input type="hidden" id="relacationId" value="${relacationId}">
            </span>
            <table class="layui-hide" id="test" lay-filter="test"></table>
            <script type="text/html" id="barDemo">
                <a class="layui-btn   layui-btn-xs" lay-event="del" onclick="sbmint('{{d.id}}')">分配车辆</a>
                <a class="layui-btn   layui-btn-xs" lay-event="del" onclick="recovery('{{d.id}}')">回收车辆</a>
            </script>
        </div>
    </div>
    <script src="${base}/js/jquery.min.js"></script>
    <script src="${base}/frame/layui/layui.all.js"></script>
    <script>
        layui.use(['laydate', 'form', 'table'], function () {
            var form = layui.form
                    , $ = layui.jquery
                    , layer = layui.layer
                    , layedit = layui.layedit
                    , laydate = layui.laydate,
                    table = layui.table;
            table.render({
                elem: '#test'
                , url: '${base}/comCarCharge/list'//数据接口
                , size: 'sm'//小尺寸的表格
                , toolbar: '#toolbarDemo'
                , title: '用户数据表'
                , cols: [[
                    {
                        field: 'id', templet: function (val) { //显示序号而不是id
                            return val.LAY_INDEX
                        }, title: '序号', width: 60
                    },
                    {field: 'carName', title: '车名', width: 100}
                    , {field: 'carModel', title: '车型号', width: 100}
                    , {field: 'carBrand', title: '车品牌', width: 110}
                    , {field: 'carRenewal', title: '续航', width: 100}
                    , {field: 'carInsurance', title: '有无保险', width: 110}
                    , {field: 'moeny', title: '车辆余额',
                        templet: function (val) {
                            return "￥ "+val.moeny
                        }, width: 110}
                    , {field: 'carPlate', title: '车牌', width: 110}
                    , {
                        field: 'relacationId', title: '是否已分配', width: 90,
                        templet: function (val) {
                            if (val.relacationId == null || val.relacationId == "") {
                                return "<span>未分配</span>"
                            } else {
                                return "<span   style='color: red'>已分配</span>"
                            }
                        }
                    }
                    , {field: 'right', title: '操作', toolbar: '#barDemo', align: 'center', width: 200}
                ]]
                , id: 'testReload'
                ,height:480
                ,page: {
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip']
                    ,theme: '#9AC747'
                    ,limit: 10
                }
                , done: function (res, curr, count) {
                    this.where = {};
                }
            });
            laydate.render({
                elem: '#test1'
                , theme: '#393D49'
            });
            laydate.render({
                elem: '#test2'
                , theme: '#393D49'
            });


        });

        function sbmint(id) {
            $.ajax({
                type: "POST",
                async: false,
                url: "${base}/comCarCharge/allotcar",
                data: {"relacationId": $("#relacationId").val(),"id":id},
                success: function (data) {
                    if (data){
                        var table =  layui.table;
                        //表刷新方法
                        table.reload('testReload', {
                            url: '${base}/comCarCharge/list'
                            , where: {} //设定异步数据接口的额外参数
                            //,height: 300
                        });
                        layer.msg("分配成功")
                        layer.closeAll('page');

                    }else {
                        layer.alert("分配失败")
                    }

                }
            })
        }

        function recovery(id) {
            $.ajax({
                type: "POST",
                async: false,
                url: "${base}/comCarCharge/recoverycar?id="+id,
                success: function (data) {
                    if (data){
                        var table =  layui.table;
                        //表刷新方法
                        table.reload('testReload', {
                            url: '${base}/comCarCharge/list'
                            , where: {} //设定异步数据接口的额外参数
                            //,height: 300
                        });
                        layer.msg("回收成功")
                        layer.closeAll('page');
                    }else {
                        layer.alert("回收失败")
                    }

                }
            })
        }

    </script>
</body>
</html>